package ruifeng.zcj.dig.ui.forum;

import android.os.Bundle;
import android.text.TextUtils;

import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import org.greenrobot.eventbus.EventBus;

import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.base.api.OSChinaApi;
import ruifeng.zcj.dig.groble.FragmentArgs;
import ruifeng.zcj.dig.ui.forum.bean.NewPost;
import ruifeng.zcj.dig.ui.forum.bean.NewPostDetail;
import ruifeng.zcj.mybase.base.BaseActivity;
import ruifeng.zcj.mybase.base.utils2.AbJsonUtil;

/**
 * 获取帖子详情
 * Created by Administrator on 2016/10/12 0012.
 */
public class ForumDetailActivity extends BaseActivity {

    protected NewPost.RowsBean mRowsBean;
    protected NewPostDetail mNewPostDetail;


    protected SendMessageFragment mSendMessageFragment;


    @Override
    public int getLayoutId() {
        return R.layout.activity_forum_detail;
    }

    @Override
    public void initView() {

        Bundle bundle = getIntent().getExtras();
        FragmentArgs args = (FragmentArgs) bundle.getSerializable("newpostBundle");
        mRowsBean = (NewPost.RowsBean) args.get("newpost");
        mSendMessageFragment = new SendMessageFragment();

        getSupportFragmentManager().beginTransaction().add(R.id.send_content, mSendMessageFragment).commit();


        OSChinaApi.getpostingsdetail("" + mRowsBean.getPostingsid(), new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    mNewPostDetail = (NewPostDetail) AbJsonUtil.fromJson(responseInfo.result, NewPostDetail.class);
                    sendNewPostDetail(mNewPostDetail);
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                showSnackBar("日志:" + s);
            }
        });
    }

    public NewPost.RowsBean getRowsBean() {
        if (mRowsBean != null) return mRowsBean;
        else return null;
    }

    public NewPostDetail getNewPostDetail() {
        if (mNewPostDetail != null) return mNewPostDetail;
        else return mNewPostDetail;
    }


    /****
     * 发送细节
     ***/
    private void sendNewPostDetail(NewPostDetail mNewPostDetail) {
        EventBus.getDefault().post(mNewPostDetail);
    }
}
